package com.zj.leetcode.medium;

/**
 * @program: algorithm
 * @description:
 * 537. 复数乘法
 * @author: Zhang Bo
 * @create: 2022-01-14 17:05
 **/
public class ComplexNumberMultiplication {
    public static void main(String[] args) {
        String num1 = "1+1i", num2 = "1+1i";
        Solution solution = new ComplexNumberMultiplication().new Solution();
        System.out.println(solution.complexNumberMultiply(num1, num2));
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public String complexNumberMultiply(String num1, String num2) {
            String[] split1 = num1.split("\\+");
            int a1 = Integer.parseInt(split1[0]);
            int b1 = 0;
            if (split1.length > 1) {
                b1 = Integer.parseInt(split1[1].replaceAll("i", ""));
            }

            String[] split2 = num2.split("\\+");
            int a2 = Integer.parseInt(split2[0]);
            int b2 = 0;
            if (split2.length > 1) {
                b2 = Integer.parseInt(split2[1].replaceAll("i", ""));
            }

            int left_true = a1 * a2;
            int left_false = b1 * b2 * (-1);
            int false_ = a1 * b2 + b1 * a2;
            return String.valueOf(left_true + left_false) + '+' + String.valueOf(false_) + "i";
        }


    }
//leetcode submit region end(Prohibit modification and deletion)

}